package com.simple.javatraining.testing.Parser;

import com.simple.javatraining.testing.testinside.answers.Answer;

import java.util.ArrayList;
import java.util.List;

public class UsersAnswerParser {
    private static final String COMMA_WITH_OPTIONAL_SPACE = ",(\\s)*";

    public static List<Answer> parseMultiplyUsersAnswer(Answer usersAnswer) {
        final String textOfUsersAnswer = usersAnswer.getTextOfAnswer();
        String[] splittedTextsOfUsersAnswer = textOfUsersAnswer.split(COMMA_WITH_OPTIONAL_SPACE);
        List<Answer> splittedUsersAnswers = new ArrayList<Answer>();
        for(String currentTextOfAnswer:splittedTextsOfUsersAnswer) {
            splittedUsersAnswers.add(new Answer(currentTextOfAnswer));
        }
        return splittedUsersAnswers;
    }
}
